package 品牌管理;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class 添加品牌 {
    public static void main(String[] args) {
        String url="jdbc:mysql://localhost:3306/db_jdbc_demo20"+
                "?characterEncoding=utf8&useSSL=false&serverTimezone=UTC";

        String user="root";
        String pass="006688";
        Connection conn=null;
        PreparedStatement pstmt=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url, user, pass);
            String sql="INSERT INTO t_brand (id,brand_name,company_name," +
                    "ordered,description,status) VALUES (?,?,?,?,?,?);";
            pstmt= conn.prepareStatement(sql);
            pstmt.setInt(1,4);
            pstmt.setString(2,"联想");
            pstmt.setString(3,"中国科技院");
            pstmt.setInt(4,400);
            pstmt.setString(5,"联想在你身边");
            pstmt.setInt(6,1);
            int i = pstmt.executeUpdate();
            if (i==1){
                System.out.println("插入成功!");
            }else {
                System.out.println("插入失败!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                pstmt.close();
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }
    }
}
